<?php // login.php -- Author Login
require_once('./inc/inc.common.php');
$tmpl 		= new mvTemplate();
$tmpl->page_title('Author Login');

if( isset($_POST['submit']) ) { // Check if the form has been submitted.
	if( empty($_POST['username']) || empty($_POST['password']) ) {
		mvError::userError('Login Error', 'You forgot to enter your username or password!');
	}else{
		// Query the database.
		$user = author::login($_POST['username'], $_POST['password']);

		if($user){ // A match was made.
				// Start the session, register the values & redirect.
				$_SESSION['user'] = $user;

				if($user->isAdmin){
					header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/a_index.php");
					exit();
				}

				header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/authors.php");
				exit();

		} else { // No match was made.
			mvError::userError('Login Error', 'The username and password entered do not match those on file.');
		}
	}
}

$tmpl->page_display('login.tpl');

?>